$(function () {
    obj.init();
});
var obj = new function () {
    'use strict';
    return {
        licenceList: null,
        iType: null,
        bFree: null,
        iState: null,
        sKey: null,
        iId: 0,
        init: function () {
            this.licenceList = new xhDataGrid($('#licenceList'), 'licence/getLicence');
            this.licenceList.parseToolbar().init();
            xhExtra.disableButton($('#bt_list_edit'), 'eu');
            this.listener();
        },
        listener: function () {
            var $this = this;
            //搜索
            $('#bt_search').click(function () {
                $this.iType = $('#licenceType').val();
                $this.bFree = $('#licenceFree').val();
                $this.iState = $('#licenceState').val();
                $this.sKey = $('#licenceKey').val();
                $this.funObj().searchList();
            });
            $('#bt_list_add').click(function () {
                $this.funObj().saveLicence();
            });
            $('#bt_list_edit').click(function () {
                $this.funObj().saveLicence();
            });

            $this.licenceList.onCheck = function (rowIndex, rowData) {
                if ($this.iId == rowData['iId']) {
                    $this.iId = 0;
                    $this.licenceList.command('unselectRow', rowIndex);
                    $('#bt_list_edit').setButtonDisable('eu');//编辑enable
                    return false;
                } else {
                    $this.iId = rowData['iId'];
                    $('#bt_list_edit').setButtonEnable('eu');//编辑enable
                }
            }


        },
        funObj: function () {
            var $this = this;
            return {
                searchList: function () {
                    $this.licenceList.reload({iType: $this.iType, bFree: $this.bFree, sKey: $this.sKey, iState:$this.iState});
                },
                saveLicence: function () {
                    var url = 'licence/licenceForm?iId='+$this.iId;
                    if ($this.iId) {
                        var title = '编辑许可证';
                    } else {
                        var title = '新增许可证';
                    }
                    window.top.xhTop.showModal({
                        title: title,
                        content: '<iframe src="'+url+'" style="width: 100%;border-style: none;padding: 0px;height: 380px"  scrolling="yes"></iframe>',
                        button: '提交',
                        backClose: false
                    });
                }
            }
        }
    }
};
